package com.IR.user.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.IR.shop.po.Cars;
import com.IR.user.service.ACarsBiz;

@Controller
public class ACarsAction {
	@Resource
	public ACarsBiz biz;
	private Cars cars;
	private List<Cars> list;
	public Cars getCars() {
		return cars;
	}
	public void setCars(Cars cars) {
		this.cars = cars;
	}
	public List<Cars> getList() {
		return list;
	}
	public void setList(List<Cars> list) {
		this.list = list;
	}
	
	/*添加用户购物车中商品的数量*/
	@RequestMapping(value="/upadateCarPronumberAdd.do")
	public void updateCarPronumberAdd(Long userid,Long proid,HttpServletResponse response) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");	
		biz.updateCarPronumberAdd(userid, proid);
		
		try {
			PrintWriter out = response.getWriter();
			out.println(1);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	/*减少用户购物车中商品的数量*/
	@RequestMapping(value="/upadateCarPronumberDecrease.do")
	public void updateCarPronumberDecrease(Long userid,Long proid,HttpServletResponse response) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");	
		biz.updateCarPronumberDecrease(userid, proid);
		try {
			PrintWriter out = response.getWriter();
			out.println(1);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@RequestMapping(value="saveCar.do")
	public void saveCar(HttpServletRequest request,HttpServletResponse response) throws IOException {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		Long userid=new Long(request.getParameter("userid"));
		Long proid=new Long(request.getParameter("proid"));
		int normsid=new Integer(request.getParameter("normsid"));
		biz.saveCar(userid, proid, normsid);
		PrintWriter out = response.getWriter();
		out.println(1);
	}
	@RequestMapping(value="updateCount.do")
	public void updateCount() {
		biz.updateCount();
	}
	@RequestMapping(value="updateNorms.do")
	public void updateNorms() {
		biz.updateNorms();
	}
	@RequestMapping(value="deleteCar.do")
	public void deleteCar(HttpServletRequest request,HttpServletResponse response) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		int carid=new Integer(request.getParameter("carid"));
		biz.deleteCar(carid);
	}	
}
